﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace IMCOM.Imagiality.ImageProcessing.Canvas2D.ROI
{
    public class SecondPointSelection : Canvas2DROIState
    {
        public SecondPointSelection(Canvas2DImageProcessor controller)
            : base(controller)
        {
        }

        public override void MouseDown(object sender, MouseEventArgs e)
        {
        }

        public override void MouseUp(object sender, MouseEventArgs e)
        {
            ROIRectangleDrawn newState = new ROIRectangleDrawn(controller);
            newState.ROIRect = ROIRect;

            SetControllerState(newState);
        }

        public override void ImagePainted(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Rectangle fullRectangle = new Rectangle(0, 0, Convert.ToInt32(g.ClipBounds.Width), Convert.ToInt32(g.ClipBounds.Height));

            if (!roiRect.Size.IsEmpty)
            {
                g.ExcludeClip(roiRect);
                g.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 0)), fullRectangle);
                g.Clip = new Region(fullRectangle);
            }
        }

        public override void MouseMoved(object sender, MouseEventArgs e)
        {
            roiRect.Size = new Size(e.X - roiRect.Location.X, e.Y - roiRect.Location.Y);

            controller.RefreshCanvas();
        }
    }
}
